package com.pj.android.brower.push.bean;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.pj.android.brower.MyApplication;
import com.pj.android.brower.push.MyNotificationManager;
import com.pj.android.brower.util.Config;

import java.util.Date;

/**
 * 打开网页
 */
public class OpenUrl extends BasePushMsg {
    public String Title;//显示在通知栏中的消息
    // public Date NoticeAt;//消息下达时间
    public String Url;//要打开的URL

    private Context context;

    private int curNotifyId = 0;

    @Override
    public void excuteAction(Context context) {
        this.context = context;
        curNotifyId = MyApplication.instance.getNotifyId();

        MyNotificationManager.Companion.getInstance().showNotification(context, "通知", Title, getDefaultIntent());

    }

    private PendingIntent getDefaultIntent() {
        try {
            Intent intent = new Intent("open_url");
            String url = Config.Companion.getInstance().getMainUrl() + Url;
            intent.putExtra("url", Config.Companion.getInstance().getMainUrl() + Url);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, curNotifyId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            return pendingIntent;
        } catch (Exception e) {
            return null;
        }
    }
}
